﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SeaBattle.UI.Web.Models;
using SeaBattle.Domain.Abstract.Services;

namespace SeaBattle.UI.Web.Controllers
{
    public class GameController : Controller
    {
        private IGameService gameService;
        private IPlayerService playerService;


        public GameController(IGameService gameService, IPlayerService playerService)
        {
            this.gameService = gameService;
            this.playerService = playerService;
        }
        //
        // GET: /Game/

        public ActionResult Index(int id)
        {
            // Get Game
            var game = gameService.GetGameById(id);
            var me = playerService.GetPlayer(User.Identity.Name);
            if (game.Opponent == null)
            {
                game.JoinOpponent(me);
            }
            //
            return View(new GameViewModel{ Game = game});
        }

        [ChildActionOnly]
        public ActionResult GameBoard()
        {
            return View("ChildActions/GameBoard");
        }
    }
}
